<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>${group == null ? '创建' : '编辑'}队伍</title>
    <%@include file="../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/ui/activity/publish_form.css">
</head><body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <%--<div class="c-time-list-header">
                <div class="r">
                    <a href="${ctx}/competition/group/list.do?projectId=${project.id}" class="layui-btn layui-btn-radius layui-btn-danger"> <i class="iconfont icon-back btn-icon"></i>返回
                    </a>
                </div>
                <div class="ovh">
					<span class="title f20" title="${project.title}">我发布的项目&nbsp;&gt;&nbsp;
						<c:if test="${fn:length(project.title) > 20}">${fn:substring(project.title,0,20)}...</c:if>
						<c:if test="${fn:length(project.title) <= 20}">${project.title}</c:if>
						&nbsp;&gt;&nbsp;队伍管理&nbsp;&gt;&nbsp;${group == null ? '创建' : '编辑'}队伍
					</span>
                </div>
            </div>--%>
            <!-- 正文请写在这里 -->
            <div class="add-form-content">
            <form id="myForm" class="layui-form mt20" method="post" action="${ctx}/competition/group/save.do">
                <div class="layui-form-item">
                    <label class="layui-form-label">编号<span class="f-verify-red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="groupNo" lay-verify="groupNo" placeholder="编号" class="layui-input" value="${group.groupNo}" style="width: 80%">
                        <input type="hidden" name="id" value="${group.id}"/>
                        <input type="hidden" name="projectId" value="${project.id}"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">名称<span class="f-verify-red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="groupName" lay-verify="groupName" placeholder="名称" class="layui-input" value="${group.groupName}" style="width: 80%">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <textarea name="remarks" class="layui-textarea" style="width: 80%">${group.remarks}</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit lay-filter="*">立即提交</a>
                        <a href="${ctx}/competition/group/list.do?projectId=${project.id}" class="layui-btn layui-btn-primary">取消</a>
                    </div>
                </div>
            </form>
            </div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
</div>


<script>
    $(function () {

        layui.use(['form'], function () {
            var form = layui.form, laydate = layui.laydate;

            //自定义验证规则
            form.verify({
                groupNo: function (value) {
                    if (value == "") {
                        return '请填写队伍编号';
                    }
                },
                groupName: function (value) {
                    if (value == "") {
                        return "请填写队伍名称";
                    }
                    var isRepeat = ajaxSubmit(value, '${project.id}', '${group.id}');
                    if (!isRepeat) {
                        return "队伍名称已存在，请重新输入";
                    }
                }
            });

            //监听提交
            form.on('submit', function (data) {
                txz.submitObject(data.elem, function (callBack) {
                    var action = $("#myForm").attr("action");
                    $.post(action, $('#myForm').serialize(), function (res) {
                        typeof callBack === 'function' && callBack();
                        if (res.success) {
                            util.layerMsgSuccess("提交成功", function () {
                                location.href = "${ctx}/competition/group/list.do?projectId=${project.id}";
                            });
                        } else {
                            util.layerMsgError("提交失败")
                        }
                    })
                }, '${group.id}');
                return false;
            });
            form.render('radio');
            function ajaxSubmit(groupName, projectId, groupId) {
                var isRepeat = false;
                $.ajax({
                    type: 'POST',
                    async: false, // 使用同步的方法
                    data: {
                        groupName: groupName,
                        projectId: projectId,
                        groupId: groupId
                    },
                    dataType: 'json',
                    success: function (data) {
                        isRepeat = data;
                    },
                    url: '${ctx}/competition/group/checkGroupName.do'
                });
                return isRepeat;
            }
        });

    })
</script>
<c:if test="${fn:length(project.title) > 20}">
    <c:if test="${empty group}">
        <script type="text/javascript">
            txz.initHeader({
                nav:[{
                    name: '我发布的项目'
                },{
                    name: '${fn:substring(project.title,0,20)}...'
                },{
                    name: '队伍管理'
                },{
                    name: '创建队伍',
                    curr: true
                }],
                btns:[{
                    name: '返回',
                    icon: 'back',
                    href: '${ctx}/competition/group/list.do?projectId=${project.id}'
                }]
            });
        </script>
    </c:if>
    <c:if test="${not empty group}">
        <script type="text/javascript">
            txz.initHeader({
                nav:[{
                    name: '我发布的项目'
                },{
                    name: '${fn:substring(project.title,0,20)}...'
                },{
                    name: '队伍管理'
                },{
                    name: '编辑队伍',
                    curr: true
                }],
                btns:[{
                    name: '返回',
                    icon: 'back',
                    href: '${ctx}/competition/group/list.do?projectId=${project.id}'
                }]
            });
        </script>
    </c:if>
</c:if>
<c:if test="${fn:length(project.title) <= 20}">
    <c:if test="${empty group}">
        <script type="text/javascript">
            txz.initHeader({
                nav:[{
                    name: '我发布的项目'
                },{
                    name: '${project.title}'
                },{
                    name: '队伍管理'
                },{
                    name: '创建队伍',
                    curr: true
                }],
                btns:[{
                    name: '返回',
                    icon: 'back',
                    href: '${ctx}/competition/group/list.do?projectId=${project.id}'
                }]
            });
        </script>
    </c:if>
    <c:if test="${not empty group}">
        <script type="text/javascript">
            txz.initHeader({
                nav:[{
                    name: '我发布的项目'
                },{
                    name: '${project.title}'
                },{
                    name: '队伍管理'
                },{
                    name: '编辑队伍',
                    curr: true
                }],
                btns:[{
                    name: '返回',
                    icon: 'back',
                    href: '${ctx}/competition/group/list.do?projectId=${project.id}'
                }]
            });
        </script>
    </c:if>
</c:if>
</body>
</html>